package org.fixies.factory;

import org.fixies.factory.GenericFactory.Factory;

import java.util.Map;


/**
 * Javaによるファクトリ
 *
 * @author Kawasaki
 */
public abstract class JavaBasedFactory implements Factory {

    private Map<String, Object> pool_ = null;

    public Object getInstance(String key) {
        return pool_.get(key);
    }

    public final void initialize() {
        Map<String, Object> pool = createPool();
        if (pool == null) {
            throw new IllegalStateException("プールがnullです。" + this.getClass().getName());
        }
        pool_ = pool;
    }

    protected abstract Map<String, Object> createPool();
}
